const util = require("../../utils/util")
const app = getApp();

// pages/order/order.js
Page({
  data: {
    api: app.globalData.api,
    uid: 0,
    displayContent: [], //包含多个对象，address count ctime hot id log mobile name pid product total uid
  },
  addComment(e){
    console.log("orderInfo")
    console.log(e.currentTarget.dataset.orderinfo)
    wx.showModal({
      editable:true,//显示输入框
      placeholderText:'这里输入评论',//显示默认信息
      success: res => {
        if (res.confirm) { //点击了确认
          console.log(res.content)//用户输入的值
          var orderinfo = e.currentTarget.dataset.orderinfo // address count ctime hot id(订单id) logo mobile name pid product total uid
          console.log("orderInfo")
          console.log(e.currentTarget.dataset.orderinfo)
          util.http('/comment/add?pid='+orderinfo.pid+'&uid='+orderinfo.uid+'&comment='+res.content, resp=>{
            console.log(resp)
            //this.setData(this.data)
            wx.switchTab({
              url: '../logs/logs',
            })
          })
        } else {
          console.log('用户点击了取消')
        }
      }
    })

  },
  deleteOrder(e){
    var orderinfo = e.currentTarget.dataset.orderinfo // address count ctime hot id(订单id) logo mobile name pid product total uid
    var that = this
    wx.showModal({
     title: '删除订单',
     content: '是否确认删除',
     success(res) {
      if (res.confirm) {
        console.log('用户点击确认')
        util.http('/order/del?id='+orderinfo.id, resp=>{
          console.log("删除执行")
          console.log(resp)
          that.setData(that.data)
          that.onLoad()
        })
       } else if (res.cancel) {
        console.log('用户点击取消')
       }
      }
     })
     that.setData(that.data)
  },
  onLoad(options) {
    this.data.uid = wx.getStorageSync('uid')
    util.http('/order/list?uid='+this.data.uid, resp=>{
      console.log("enter order")
      console.log(resp)
      this.data.displayContent = resp.reverse();
      this.setData(this.data)
    })
    this.setData(this.data)
  },
})